package com.my.dao;

import com.my.UserInfo;
import com.my.util.DBCon;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserInfoModel  {
    private DBCon dbCon;

    public UserInfoModel(){
        dbCon=new DBCon();
    }

    public boolean insert(UserInfo userInfo){
        boolean result=false;
        //数据库连接对象
        Connection con=dbCon.getConnection();
        String sql="insert into tb_userInfo(userName,password,address) values(?,?,?)";
        try{
            //将用户信息插入到表tb_userInfo中
            PreparedStatement pstmt=con.prepareStatement(sql);
            pstmt.setString(1,userInfo.getUserName());
            pstmt.setString(2,userInfo.getPassword());
            pstmt.setString(3,userInfo.getAddress());
            int i=pstmt.executeUpdate();
            if(i>0){
               result=true;
            }
        }catch(SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
}
